package com.alks.function.controller.finance.borad;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.common.utils.MinIoUtil;
import com.alks.entity.data.entity.ExportPlanInfo;
import com.alks.entity.data.entity.PcBoard;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.service.boardService.BoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * @author:hxl
 * @create: 2024-08-03 14:49
 * @Description:
 */

@ApiRestController("/board")
@Api(tags = "订单船坞作业")
public class PcBoardController {
    @Autowired
    MinIoUtil minIoUtil;
    @Autowired
    private BoardService boardService;

    //查看文件附件
    @PostMapping("/downloadAnnex")
    @ApiOperation(value ="下载附件")
    @WebLogger
    public void downloadBoardFile(HttpServletResponse response, @RequestBody PcBoard pcBoard){
        minIoUtil.download("excel",pcBoard.getFilePath(),response);
    }

    //上传文件附件
    @PostMapping("/uploadAnnex")
    @ApiOperation(value ="上传附件")
    @WebLogger
    public ResponseInfo uploadBoardFile(MultipartFile file,@RequestParam String invoiceNo){
        return boardService.uploadBoardFile(file,invoiceNo);
    }
    //删除文件附件
    @PostMapping("/deleteAnnex")
    @ApiOperation(value ="删除附件")
    @WebLogger
    public ResponseInfo deleteBoardFile(@RequestBody PcBoard pcBoard){
        return boardService.deleteBoardFile(pcBoard);
    }

    //附件查询
    @PostMapping("/annexList")
    @ApiOperation(value ="附件查询")
    @WebLogger
    public ResponseInfo annexList(@RequestParam String invoiceNo){
        return boardService.annexList(invoiceNo);
    }

    //订单船坞作业查询
    @PostMapping("/queryBoard")
    @ApiOperation(value ="订单船坞作业查询")
    @WebLogger
    public ResponseInfo queryBoard(@RequestBody ExportPlan  exportPlan){
        return boardService.queryBoard(exportPlan);
    }

    //出货明细查询
    @PostMapping("/queryBoardDetail")
    @ApiOperation(value ="出货明细查询")
    @WebLogger
    public ResponseInfo queryBoardDetail(@RequestBody ExportPlanInfo exportPlanInfo){
        return boardService.queryBoardDetail(exportPlanInfo);
    }
    //出货明细编辑
    @PostMapping("/editBoardDetail")
    @ApiOperation(value ="出货明细编辑")
    @WebLogger
    public ResponseInfo editBoardDetail(@RequestBody ExportPlanInfo exportPlanInfo){
        return boardService.editBoardDetail(exportPlanInfo);
    }
    //编辑保存

    @PostMapping("/editBoardSaveData")
    @ApiOperation(value ="编辑保存 没有检核的才能编辑")
    @WebLogger
    public ResponseInfo editBoardSaveData(@RequestBody List<ExportPlan> exportPlan){
        return boardService.editBoardSaveData(exportPlan);
    }

    //检核
    @PostMapping("/updateCfmFlag")
    @ApiOperation(value ="检核")
    @WebLogger
    public ResponseInfo updateCfmFlag(@RequestParam String detailUid, @RequestParam String invoiceNo, @RequestParam String cfmFlag){
        return boardService.updateCfmFlag(detailUid,invoiceNo,cfmFlag);
    }

    //其他应收保存
    @PostMapping("/otherSaveData")
    @ApiOperation(value ="其他应收保存")
    @WebLogger
    public ResponseInfo otherSaveData(@RequestBody List<ExportPlan> exportPlan){
        return boardService.otherSaveData(exportPlan);
    }

    //删除船坞订单
    @PostMapping({"/delete"})
    @ApiOperation(value ="删除船坞订单")
    @WebLogger
    public ResponseInfo deleteDetail(@RequestBody ExportPlan exportPlan){
        return boardService.deleteDetail(exportPlan);
    }

    //填充信用证号

    @PostMapping({"/update/creditNo"})
    @ApiOperation(value ="填充信用证号")
    @WebLogger
    public ResponseInfo updateCreditNo(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date shipDate,@RequestParam(required = false) String creditNo, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date deliveryDate, @RequestBody List<ExportPlan> records){
        return boardService.updateCreditNo(creditNo, deliveryDate, records, shipDate);
    }

    //导出船坞作业
    @PostMapping("/downloadBoard")
    @ApiOperation(value ="导出船坞作业")
    @WebLogger
    public void downloadBoard(HttpServletResponse response,@RequestBody ExportPlan  exportPlan) throws IOException {
        boardService.downloadBoard(response,exportPlan);
    }
}
